package com.itheima.bigevents.mapper;

import com.itheima.bigevents.pojo.User;
import org.apache.ibatis.annotations.*;

@Mapper // 标注为mybatis的mapper接口
public interface UserMapper {

    // 根据用户名查询用户
    @Select("SELECT * FROM user WHERE username = #{username}")
    User findByUsername(String username);

    // 添加用户
    @Insert("INSERT INTO user(username, password,create_time,update_time) VALUES(#{username}, #{md5Password},now(),now())")
    void add(String username, String md5Password);

    @Update("UPDATE user SET NICKNAME = #{nickname}, EMAIL = #{email},update_time = now() WHERE ID = #{id}") // 更新用户信息
    void update(User user);

    @Delete("DELETE FROM user WHERE ID = #{id}") // 删除用户
    void delete(Integer id);

    @Update("UPDATE user SET user_pic = #{avatarUrl},update_time = now() WHERE ID = #{id}") // 更新用户头像
    void updateAvatar(String avatarUrl, Integer id);
    @Update("UPDATE user SET password = #{md5Password},update_time = now() WHERE ID = #{id}") // 更新用户密码
    void updatePassword(String md5Password, Integer id);
}
